import { InputQuestion, QuestionBase, TimeQuestion, SelectQuestion, RadioQuestion, TextQuestion } from '@/components/public-template';
import { TextTable } from '@/components/public-template';
import { TableBase } from '@/components/public-template';
import { Api as ApiSystem } from '@/config/api/system';
import { Api as ApiResource } from '@/config/api/resourceFileInfo';
import { changeByte } from '@/utils/common';

class IndexService {
  getQuestions() {
    const questions: QuestionBase<any>[] = [
      new TextQuestion({
        key: 'billCode',
        label: '单据编号',
        value: null
      }),
      new TextQuestion({
        key: 'creator',
        hide: true,
        value: null
      }),
      new TextQuestion({
        key: 'creatorName',
        label: '创建人',
        value: null
      }),
      new TextQuestion({
        key: 'department',
        hide: true,
        value: null
      }),
      new TextQuestion({
        key: 'departmentName',
        label: '创建部门',
        value: null
      }),
      new TextQuestion({
        key: 'createdTime',
        label: '创建时间',
        value: null
      }),
      new TextQuestion({
        key: 'remindDatetime',
        label: '到期提醒时间',
        value: null
      })
    ];
    return questions;
  }
  getCreatorQuestions() {
    const questions: QuestionBase<any>[] = [
      new SelectQuestion({
        key: 'adminBy',
        label: '档案管理员',
        required: true,
        prompt: '请选择',
        value: null,
        state: {
          url: ApiSystem.subjectListSimple,
          protType: 'post',
          nameKey: 'nickName',
          nameValue: 'id',
          showSearch: true,
          placement: 'topLeft',
          optionFilterProp: 'label'
        }
      }),
      new TimeQuestion({
        key: 'plannedHandoverTime',
        label: '计划交接时间',
        required: true,
        prompt: '请选择',
        value: null,
        type: 'alone',
        state: {
          showTime: true,
          format: 'YYYY-MM-DD HH:mm',
          valueFormat: 'YYYY-MM-DD HH:mm:ss',
          placement: 'topLeft'
        }
      })
    ];
    return questions;
  }
  getViewCreatorQuestions() {
    const questions: QuestionBase<any>[] = [
      new TextQuestion({
        key: 'adminByName',
        label: '档案管理员',
        value: null
      }),
      new TextQuestion({
        key: 'plannedHandoverTime',
        label: '计划交接时间',
        value: null
      })
    ];
    return questions;
  }
  getCommentQuestions({ showType }) {
    const questions: QuestionBase<any>[] = [
      showType == 'AUDIT'
        ? new RadioQuestion({
            key: 'applyResult',
            label: '意见',
            required: true,
            prompt: '请选择',
            value: 1,
            options: [
              {
                label: '通过',
                value: 1
              },
              {
                label: '驳回',
                value: 2
              }
            ]
          })
        : new RadioQuestion({
            key: 'isReceive',
            label: '意见',
            required: true,
            prompt: '请选择',
            value: true,
            options: [
              {
                label: '通过',
                value: true
              },
              {
                label: '驳回',
                value: false
              }
            ]
          }),
      new InputQuestion({
        key: 'remark',
        label: '备注',
        value: null
      })
    ];
    return questions;
  }
  getTables({ showType }) {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'num',
        value: '序号',
        type: 'index'
      }),
      new TextTable({
        key: 'name',
        value: '名称',
        type: 'router',
        state: {
          type: 'local'
        }
      }),
      new TextTable({
        key: 'size',
        value: '大小',
        type: 'custom',
        columns: {
          customRender: (data: any) => {
            return changeByte(data.value);
          }
        }
      }),
      new TextTable({
        key: 'createdTime',
        value: '上传时间'
      }),
      new TextTable({
        key: 'actions',
        value: '操作',
        handle:
          showType == 'VIEW'
            ? [
                {
                  type: 'local',
                  text: '下载',
                  class: 'text-primary',
                  url: '/url',
                  params: [{ id: 'id' }],
                  state: {
                    type: 'download'
                  }
                }
              ]
            : [
                {
                  type: 'local',
                  text: '删除',
                  class: 'text-primary',
                  url: '/url',
                  params: [{ id: 'id' }],
                  state: {
                    type: 'delete'
                  }
                }
              ]
      })
    ];
    return tables;
  }
  getIcons({ showType, handleReceiveImport }) {
    const icons: TableBase<any>[] =
      showType == 'VIEW'
        ? []
        : [
            new TextTable({
              key: 'upload',
              value: '导入',
              type: 'primary',
              class: 'icon-upload',
              state: {
                url: ApiResource.resourceUploadFiles,
                downloadRule: '仅允许上传excel格式；文件大小不超过10M',
                tipText: '请导入归档接收确认证明文件',
                tipClass: 'icon-help-circle',
                limit: true,
                callback: (data) => {
                  handleReceiveImport && handleReceiveImport(data);
                }
              }
            })
          ];
    return icons;
  }
  getEnterTables() {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'num',
        value: '行号',
        type: 'index'
      }),
      new TextTable({
        key: 'type',
        value: '载体形式',
        type: 'dictionary',
        state: {
          filterName: 'CARRIER_TYPE'
        }
      }),
      new TextTable({
        key: 'source',
        value: '文件来源',
        type: 'dictionary',
        state: {
          filterName: 'ARCHIVES_SOURCE'
        }
      }),
      new TextTable({
        key: 'name',
        value: '文件名称'
      }),
      new TextTable({
        key: 'code',
        value: '文件编码'
      }),
      new TextTable({
        key: 'filePages',
        value: '文件页数'
      }),
      new TextTable({
        key: 'filesTypeName',
        value: '档案类型'
      }),
      new TextTable({
        key: 'secretLevel',
        value: '保密等级',
        type: 'dictionary',
        state: {
          filterName: 'SECRET_LEVEL'
        }
      }),
      new TextTable({
        key: 'eachOther',
        value: '互见号'
      }),
      new TextTable({
        key: 'fromDate',
        value: '形成时间'
      }),
      new TextTable({
        key: 'chargeUserIdName',
        value: '责任者'
      }),
      new TextTable({
        key: 'retentionPeriodDate',
        value: '保管期限',
        type: 'dictionary',
        state: {
          filterName: 'DMS_ARCHIVES_FILE_LIST_RETENTION_PERIOD_DATE'
        }
      }),
      new TextTable({
        key: 'toDepartmentName',
        value: '归档部门'
      }),
      new TextTable({
        key: 'toDate',
        value: '归档时间'
      }),
      new TextTable({
        key: 'remark',
        value: '说明'
      }),
      new TextTable({
        key: 'storageLocationName',
        value: '存放地点'
      }),
      new TextTable({
        key: 'boxCode',
        value: '档案盒'
      }),
      new TextTable({
        key: 'partNo',
        value: '件号'
      }),
      new TextTable({
        key: 'filesBoxCode',
        value: '档案编码'
      }),
      new TextTable({
        key: 'summary',
        value: '提要'
      }),
      new TextTable({
        key: 'keyword',
        value: '关键词'
      })
    ];
    return tables;
  }
}

export default new IndexService();
